import React, { Component } from "react";
// 一切皆组件
import { Link, Route, Switch } from "react-router-dom";
// 如果我们的项目想使用路由，那么整个项目都要用BrowserRouter组件套住
// Link组件是用来做跳转的, 需要一个to属性
// 用Route组件来做组件的渲染, path属性是对应的路径，component用于渲染哪个组件
// exact属性表示精准匹配

// react路由是包容性路由，vue是排他性路由
// Switch是分支匹配，将包容性路由变成排他性路由

class Home extends Component {
  render() {
    return <div>首页</div>;
  }
}
class About extends Component {
  render() {
    return <div>关于页</div>;
  }
}
class Mine extends Component {
  render() {
    return <div>我的页</div>;
  }
}

class Basic extends Component {
  state = {};
  render() {
    return (
      <>
        <h3>路由基础</h3>
        <ul>
          <li>
            <Link to="/">home</Link>
          </li>
          <li>
            <Link to="/about">about</Link>
          </li>
          <li>
            <Link to="/mine">mine</Link>
          </li>
        </ul>

        <Switch>
          <Route path="/" component={Home} exact></Route>
          <Route path="/about" component={About}></Route>
          <Route path="/mine" component={Mine}></Route>
        </Switch>
      </>
    );
  }
}

export default Basic;
